package com.example.doctor.service;
import com.alibaba.boot.dubbo.annotation.DubboConsumer;
import com.example.pojo.GdArticleWithBLOBs;
import com.example.pojo.GdInfoDic;
import com.example.service.RpcAtileService;
import com.example.service.RpcDoctorService;
import com.example.vo.ArticleReturnVo;
import com.example.vo.ArticleVO;
import com.example.vo.DoctorDetailsReturnVo;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by LENOVO on 2018/9/27.
 */
@Component
public class ArticleServiceImpl implements ArticleService {

    @DubboConsumer
    private RpcAtileService rpcAtileService;

    @DubboConsumer
    private RpcDoctorService rpcDoctorService;

    @Override
    public List<GdInfoDic> getArticleType(Map map) throws Exception {
        return rpcAtileService.getArticleType(map);
    }

    @Override
    public  List<ArticleReturnVo> getArticleList(ArticleVO articleVO) throws Exception {

        List<ArticleReturnVo> articleReturnVoList=new ArrayList<>();
        DoctorDetailsReturnVo doctorDetailsReturnVo=null;
        List<GdArticleWithBLOBs> list=rpcAtileService.getArticleList(articleVO);
        for(GdArticleWithBLOBs gdArticleWithBLOBs:list)
        {
           doctorDetailsReturnVo=rpcDoctorService.selectDetailsById(gdArticleWithBLOBs.getDoctorid());
           ArticleReturnVo articleReturnVo=new ArticleReturnVo();
           articleReturnVo.setId(gdArticleWithBLOBs.getId());
           articleReturnVo.setAbstracts(gdArticleWithBLOBs.getAbstracts());
           articleReturnVo.setCollectionnumber(gdArticleWithBLOBs.getCollectionnumber());
           articleReturnVo.setDoctorname(gdArticleWithBLOBs.getDoctorname());
           articleReturnVo.setHospitalName(doctorDetailsReturnVo.getHospitalName());
           articleReturnVo.setReadnumber(gdArticleWithBLOBs.getReadnumber());
           articleReturnVo.setTitle(gdArticleWithBLOBs.getTitle());
           articleReturnVoList.add(articleReturnVo);
         }
      return  articleReturnVoList;
    }

    @Override
    public ArticleReturnVo getArticleDetleById(String id) throws Exception {

        ArticleReturnVo articleReturnVo=new ArticleReturnVo();
        GdArticleWithBLOBs gdArticleWithBLOBs=rpcAtileService.getArticleDetleById(Long.parseLong(id));
        DoctorDetailsReturnVo doctorDetailsReturnVo=rpcDoctorService.selectDetailsById(gdArticleWithBLOBs.getDoctorid());
        articleReturnVo.setId(gdArticleWithBLOBs.getId());
        articleReturnVo.setAbstracts(gdArticleWithBLOBs.getAbstracts());
        articleReturnVo.setCollectionnumber(gdArticleWithBLOBs.getCollectionnumber());
        articleReturnVo.setDoctorname(gdArticleWithBLOBs.getDoctorname());
        articleReturnVo.setHospitalName(doctorDetailsReturnVo.getHospitalName());
        articleReturnVo.setReadnumber(gdArticleWithBLOBs.getReadnumber());
        articleReturnVo.setTitle(gdArticleWithBLOBs.getTitle());
        articleReturnVo.setTitle(gdArticleWithBLOBs.getContent());
        return  articleReturnVo;
    }
}
